package com.kk.quyan.common.handler;

import com.kk.quyan.common.R;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @description:
 * @author: Kk
 * @create: 2020-11-21 17:29
 **/
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    private static final Logger logger=LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public R error(Exception e){
        logger.info(e.getMessage());
        return R.error().setMessage("操作错误");
    }

    @ExceptionHandler(CustomException.class)
    public R error(CustomException e){
        logger.info("异常信息->状态码: {} 信息: {}",e.getCode(),e.getMsg());
        return R.error().setCode(e.getCode()).setMessage(e.getMessage());
    }
}
